package com.freshcity.manager.support
{
	import com.pblabs.engine.PBE;
	import com.pblabs.engine.resource.SWFResource;
	
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.ui.Mouse;
	import com.freshcity.manager.CursorManager;

	public class CursorManagerImpl extends Sprite
	{
		[Embed(source='../assets/core/swfs/cursorskin.swf',symbol='CursorSkin')]
		public var CursorSkin:Class;	
		private var _cursorSkin:MovieClip;
		
		private var _cursorStyle:String;		

		public function CursorManagerImpl()
		{
			_cursorSkin = new CursorSkin();
			_cursorSkin.gotoAndStop(0);
			this.addEventListener(Event.ADDED_TO_STAGE, this.addedToStageHandler);
		}
		
		public function addedToStageHandler(arg1:Event):void
		{
			this.mouseChildren = false;
			this.mouseEnabled = false;
			this._cursorSkin.mouseChildren = false;
			this._cursorSkin.mouseEnabled = false;
			this.addChild(this._cursorSkin);
		}
		
		private function onMouseMoveHandler(arg1:MouseEvent):void
		{
			this._cursorSkin.x = arg1.stageX;
			this._cursorSkin.y = arg1.stageY;
			arg1.updateAfterEvent();
		}
		
		public function get cursorStyle():String
		{
			return this._cursorStyle;
		}
		
		public function set cursorStyle(arg1:String):void
		{
			this._cursorStyle = arg1;
			if (this._cursorStyle != CursorManager.NO_CURSOR) 
			{
				if (this.contains(this._cursorSkin) == false) 
				{
					this.addChild(this._cursorSkin);
				}
				Mouse.hide();
				this._cursorSkin.gotoAndStop(arg1);
				this._cursorSkin.x = mouseX;
				this._cursorSkin.y = mouseY;
				PBE.mainStage.addEventListener(MouseEvent.MOUSE_MOVE, this.onMouseMoveHandler);
			}
			else 
			{
				if (this.contains(this._cursorSkin)) 
				{
					this.removeChild(this._cursorSkin);
				}
				Mouse.show();
				PBE.mainStage.removeEventListener(MouseEvent.MOUSE_MOVE, this.onMouseMoveHandler);
			}
		}

	}
}